﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Xml.Serialization;
using System.Collections.ObjectModel;
using System.Data.SqlClient;
using System.Reflection;

namespace EntityMap.Meta
{
    public class ChangeStatement : SqlStatement
    {
        public override object Process<T>( Context ctx )
        {
            bool result = false;

            using( SqlConnection conn = new SqlConnection( ctx.Mapper.ConnectionString ) )
            {
                SqlCommand cmd =  new SqlCommand( this.Command, conn );

                if( ctx.ParameterMap != null )
                {
                    cmd.Parameters.AddRange( ctx.ParameterMap.GetSqlParameters( ctx.Parameter ) );
                }              
               
                conn.Open();

                int effect = cmd.ExecuteNonQuery();

                if( effect > 0 )
                {
                    result = true;
                }
            }

            return result;
        }
    }
}
